/*******************************************************************************
 *
 *      Filename: Controller.cpp
 *   Description: See Controller.h
 *        Author: [kb]ypp
 *    Created at: November 20, 2005
 * Last modified: 
 *
 ******************************************************************************/

#include "Controller.h"
#include <cassert>

#include <iostream>
using namespace std;
#include "Log.h"

/*******************************************************************************
 *
 * Keyboard class implementation
 *
 ******************************************************************************/

// Code here
// ...

Keyboard::Keyboard()
{
	// Release all buttons:
	for ( int i = 0; i < KEYS_COUNT; ++i )
		keys[ i ] = false;
}

void Keyboard::keyPress( int k )
{
	assert( 0 <= k && k < KEYS_COUNT );
	keys[ k ] = true;
	cout << "key: " << k << "\t" << "pressed " << endl;
}

void Keyboard::keyRelease( int k )
{
	assert( 0 <= k && k < KEYS_COUNT );
	keys[ k ] = false;
	cout << "key: " << k << "\t" << "released" << endl;
}

/*******************************************************************************
 *
 * Mouse class implementation
 *
 ******************************************************************************/

Mouse::Mouse()
	: x( 0 ), y( 0 ), buttons( 0 )
{
}

void Mouse::buttonPress( int btn )
{
	buttons += btn;
	if ( btn & MB_LEFT )
		LOG_DEBUG( "Left mouse button pressed" );
	else if ( btn & MB_MIDDLE )
		LOG_DEBUG( "Middle mouse button pressed" );
	else if ( btn & MB_RIGHT )
		LOG_DEBUG( "Right mouse button pressed" );
	else if ( btn & MB_SCROLL_UP )
		LOG_DEBUG( "Mouse scroll up pressed" );
	else if ( btn & MB_SCROLL_DOWN )
		LOG_DEBUG( "Mouse scroll down pressed" );
	else
		LOG_WARNING( "Unknown mouse button pressed" );
	//cout << "button: " << btn << "\t" << "pressed " << endl;
}

void Mouse::buttonRelease( int btn )
{
	buttons -= btn;
	if ( btn & MB_LEFT )
		LOG_DEBUG( "Left mouse button released" );
	else if ( btn & MB_MIDDLE  )
		LOG_DEBUG( "Middle mouse button released" );
	else if ( btn & MB_RIGHT )
		LOG_DEBUG( "Right mouse button released" );
	else if ( btn & MB_SCROLL_UP )
		LOG_DEBUG( "Mouse scroll up released" );
	else if ( btn & MB_SCROLL_DOWN )
		LOG_DEBUG( "Mouse scroll down released" );
	else
		LOG_WARNING( "Unknown mouse button released" );

	//cout << "button: " << btn << "\t" << "released" << endl;
}

void Mouse::moveCursor( int xpos, int ypos )
{
	x = xpos;
	y = ypos;
	cout << "x: " << x << "\t" << "y: " << y << endl;
}
